﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOHVote.Common;
using System.IO;
using System.Data;
using BOHVote.BLL;

namespace BOH.Information
{
    public partial class PPTUpload : System.Web.UI.Page
    {
       
               
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string strApplyID = Request.QueryString["ID"];
                fillData(strApplyID);
            }
        }


        protected void fillData(string strApplyID)
        {
            DataSet dstApply = ApplyClass.getApplyByID(strApplyID);
            if (dstApply != null && dstApply.Tables.Count > 0 && dstApply.Tables[0].Rows.Count > 0)
            {
                labApplyName.Text = dstApply.Tables[0].Rows[0]["Apply_Name"].ToString();
                labApplyIDCard.Text = dstApply.Tables[0].Rows[0]["IDCard"].ToString().Trim();
                if (!string.IsNullOrEmpty(dstApply.Tables[0].Rows[0]["UnitID"].ToString().Trim()))
                    labApplyUnit.Text = UnitClass.getUnitName(dstApply.Tables[0].Rows[0]["UnitID"].ToString().Trim());
                if (!string.IsNullOrEmpty(dstApply.Tables[0].Rows[0]["GovernID"].ToString().Trim()))
                    labApplyUnit.Text = UnitClass.GetGovernName(dstApply.Tables[0].Rows[0]["GovernID"].ToString().Trim());
                labApplyJob.Text = OtherClass.getJobRankName(dstApply.Tables[0].Rows[0]["JobRankID"].ToString().Trim());

                if (dstApply.Tables[0].Rows[0]["ApplyPPT"].ToString().Trim().Length > 0)
                {
                    string LoadFullPath = common.getAppSetting("FolderforLoadPath") + "/" + ((string)Session["ApplyPeriod"]).Trim();
                    string LoadPath = LoadFullPath + "/" + dstApply.Tables[0].Rows[0]["ApplyPPT"].ToString().Trim();
                    ShowPPT.Visible = true;
                    ShowPPT.NavigateUrl = LoadPath;
                }
            }
        }

        protected void butSavePPT_Click(object sender, EventArgs e)
        {
            if (labApplyIDCard.Text.Trim().Length > 0 && ((string)Session["ApplyPeriod"]).Length > 0)
            {
                string strFullFolderPath = common.getAppSetting("FolderforSavePath") + "\\" + ((string)Session["ApplyPeriod"]).Trim();
                string LoadFullPath = common.getAppSetting("FolderforLoadPath") + "/" + ((string)Session["ApplyPeriod"]).Trim();
                common.CreateFolder(strFullFolderPath);
                HttpFileCollection hfc = Request.Files;
                for (int i = 0; i < hfc.Count; i++)
                {
                    if (hfc.Keys[i].ToLower().Trim() == "fileppt")
                    {
                        HttpPostedFile hpf = hfc[i];
                        if (hpf.ContentLength > 0)
                        {
                            string FileFullPath = strFullFolderPath + "\\" + labApplyIDCard.Text.Trim() + System.IO.Path.GetExtension(hpf.FileName);
                            if (File.Exists(FileFullPath))
                            {
                                File.Delete(FileFullPath);
                            }
                            hpf.SaveAs(FileFullPath);
                            string LoadPath = LoadFullPath + "/" + labApplyIDCard.Text.Trim() + System.IO.Path.GetExtension(hpf.FileName);
                            string PPTFileName = labApplyIDCard.Text.Trim() + System.IO.Path.GetExtension(hpf.FileName);
                            hiddenPPTFile.Value = PPTFileName;
                            ShowPPT.Visible = true;
                            ShowPPT.NavigateUrl = LoadPath;
                        }
                    }
                }
            }
        }


        protected void butSave_Click(object sender, EventArgs e)
        {
            string strApplyID = Request.QueryString["ID"];
            if (!string.IsNullOrEmpty(strApplyID) && !string.IsNullOrEmpty(hiddenPPTFile.Value))
            {
                ApplyClass.ApplyPPTUpdate(strApplyID, hiddenPPTFile.Value);
            }
        }
    }
}
